<template>
  <el-card shadow="never" class="aui-card--fill">
    <el-form :inline="true" v-model="SearchForm" clearable  @keydown.enter.native.prevent="getDataList()">
      <el-form-item>
        <el-input v-model="SearchForm.name" placeholder="学号或教职工号" clearable></el-input>
      </el-form-item>
      <el-form-item>
              <el-select v-model="SearchForm.status" placeholder="指导记录来源">
                  <el-option label="学生" value=1></el-option>
                  <el-option label="老师" value=2></el-option>
                  <el-option label="所有指导记录" value=3></el-option>
              </el-select>
          </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <el-button  type="danger" @click="del()"
          :disabled="dataListSelections.length <= 0">批量删除</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="dataList" border v-loading="dataListLoading" @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column type="selection" header-align="center" align="center" width="50">
      </el-table-column>
      <el-table-column prop="name" header-align="center" align="center" label="姓名">
      </el-table-column>
      <el-table-column prop="username" header-align="center" align="center" label="学号或教职工号">
      </el-table-column>
      <el-table-column prop="reTeacher" header-align="center" align="center" label="指导教师">
      </el-table-column>
      <el-table-column fixed="right" header-align="center" align="center" width="150" label="操作">
        <template slot-scope="scope">
          <el-button  type="text" size="small" @click="detailed(scope.row.recordsId)">查看详情</el-button>
          <el-button size="mini"  type="text" @click="del(scope.row.recordsId)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </el-card>
</template>

<script>
import servicesApi from '@/services/servicesApi';
import AddOrUpdate from '@/views/Teacher/ttcheck-deguidance'
export default {
  data() {
    return {
      SearchForm: {
        name: '',
        status: null,
      },
      dataList: [
        { 
         recordsId: '',
         name: '',
         username: '',
         state: '',
         reTeacher: '',
         reHarvest: '', 
         reAdvise: '', 
         reTarget: '', 
         department: '',
         stuSituation: '', 
         reImfor: '', 
         gmtCreate: '', 
         gmtModified: '',
         status: null
         }
      ],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      deleteList: [],
      deleteList: {
              list: []
           },
      addOrUpdateVisible: false, // 新增／更新，弹窗visible状态
    }
  },
  activated() {
    this.getDataList()
  },
  created() {
    this.getDataList()
  },
  components: {
  AddOrUpdate
},
  methods: {
      //删除
      del(id) {
      let roleIds = id ? [id] : this.dataListSelections.map(item => {
      return item.recordsId
    })
    this.deleteList.list = roleIds
      servicesApi.delTTguidance(this.deleteList).then(res => {
          // console.log(res.data)
          let code = res.data.code
          if (code === 200) {
              this.$message({
                  message: '删除成功',
                  type: 'success',
                  duration: 1000,
                  onClose: () => {
                      this.getDataList()
                  }
              })
          } else {
              this.$message({
                  message: res.data.msg,
                  type: 'danger',
                  duration: 1000,
                  onClose: () => {
                      this.getDataList()
                  }
              })
          }
      })
  },
  //查看详细信息
      detailed(id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        // this.$refs.addOrUpdate.dataForm.id = id
        this.$refs['addOrUpdate'].init(id)
      })
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true
      let pageInfo = {
        current: this.pageIndex,
        size: this.pageSize,
        username: this.SearchForm.name,
        state: this.SearchForm.status === null?3:this.SearchForm.status,
      }
      servicesApi.getTTguidance(pageInfo).then(res => {
        // console.log(res.data)
        let code =res.data.code
        let data = res.data.data
        if (code===200) {
          this.dataList = data.list
          this.totalPage = data.total
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val
      this.getDataList()
    },
    // 多选
    selectionChangeHandle(val) {
      this.dataListSelections = val
      // console.log('多选')
      // console.log(this.dataListSelections)
    },
  }
}
</script>
